#pragma once

#include "dut/WinMin.h"

#include "dut/DXTrace.h"

using namespace Microsoft::WRL;

namespace Dut
{
    struct MeshIndice
    {

        ComPtr<ID3D11Buffer> m_pVertexBuffer;          
        ComPtr<ID3D11Buffer> m_pIndexBuffer;           
        DXGI_FORMAT m_IndiceType;
        unsigned int m_VertexStride;
        unsigned int m_NumIndices;

        struct Desc
        {
            const void* vertices;
            unsigned int vertexStride;
            unsigned int vertexSize;

            const void* indices;
            unsigned int indiceStride;
            unsigned int indiceSize;
            unsigned int numIndices;
        };

        template<typename VertexType, typename IndiceType>
        HRESULT Create(ID3D11Device* device,const std::vector<VertexType>& vertices, const std::vector<IndiceType>& indices)
        {
            Desc desc;

            desc.vertices = &vertices[0];
            desc.vertexStride = sizeof(VertexType);
            desc.vertexSize = sizeof(VertexType) * vertices.size();

            desc.indices = &indices[0];
            desc.numIndices = indices.size();
            desc.indiceStride = sizeof(IndiceType);
            desc.indiceSize = indices.size() * sizeof(IndiceType);
            
            return Create(device, desc);
        }
        HRESULT Create(ID3D11Device* device,const Desc& desc);
        void DrawIndexed(ID3D11DeviceContext* context);
	
    private:
        DXGI_FORMAT GetIndiceType(const int& sz);

    };

}